<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>支付</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <script src="http://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>

    <script th:inline="javascript">

        var timestamp = [[${timestamp}]];
        var signature = [[${signature}]];
        var prepay_id = [[${prepay_id}]];
        var paySign = [[${paySign}]];
        wx.config({
            debug: false,
            appId: 'wx5433e72fcae4f1e5',
            timestamp: timestamp,
            nonceStr: 'Wm3WZYTPz0wzccnW',
            signature: signature,
            jsApiList: [
                'onMenuShareAppMessage',
                'closeWindow',
                'chooseWXPay'
            ]
        });


        function onBridgeReady(){
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest',{
                    "appId" :"wx5433e72fcae4f1e5",     //公众号名称，由商户传入
                    "timeStamp": timestamp,         //时间戳，自1970年以来的秒数
                    "nonceStr":"Wm3WZYTPz0wzccnW", //随机串
                    "package":"prepay_id=" + prepay_id,
                    "signType":"MD5",         //微信签名方式：
                    "paySign":paySign //微信签名
                },
                function(res){
                    if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                        var element=document.getElementById("aa");
                        element.innerHTML="支付成功";
                        wx.closeWindow();
                    }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                }
            );
        }
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        }else{
            onBridgeReady();
        }


    </script>

<body>
    <div id = "aa" style="align-content: center"></div>

</body>
</html>